const util = require('../../../../utils/util.js')

//发送聊天消息
function msgSend(chatRoomId, content, callback) {
  // var userId = getApp().globalData.userId
  var userId = "2"
  getApp().func.Post(false, getApp().api.user__msg_put, { "chatRoomId": chatRoomId, "content": content, },
  function(data) {
      typeof callback == "function" && callback(data)
  },
  function(error) {
    console.log(error)
    wx.showToast({
      title: error.data.message,
      icon: 'none',
      duration: 2000
    })
  })
};

//创建聊天室
function msgRoomCreate(toUserId, callback) {
  // var userId = getApp().globalData.userId
  var userId = "2"
  getApp().func.Post(false, getApp().api.user__msg_room_put, {"toUserId" : toUserId},
  function(data) {
      typeof callback == "function" && callback(data)
  },
  function(error) {
    console.log(error)
    wx.showToast({
      title: error.data.message,
      icon: 'none',
      duration: 2000
    })
  })
};

//获取房间消息记录
function msgRecordGet(page, chatRoomId, callback) {
  // var userId = getApp().globalData.userId
  var userId = "2"
  getApp().func.Get(false, getApp().api.user_msg_records, {"startPage" : page, "chatRoomId": chatRoomId },
  function(data) {
      typeof callback == "function" && callback(data)
  },
  function(error) {
    console.log(error)
    wx.showToast({
      title: error.data.message,
      icon: 'none',
      duration: 2000
    })
  })
};

module.exports = {
  msgRoomCreate: msgRoomCreate,
  msgSend: msgSend,
  msgRecordGet: msgRecordGet,

};